package com.example.test;


import java.util.concurrent.CountDownLatch;

/**
 * The type Count down latch demo.
 *
 * @author xiejp on 2022/5/6
 */
public class CountDownLatchDemo {
    /**
     * The entry point of application.
     *
     * @param args the input arguments
     */
    public static void main(String[] args) throws InterruptedException {

        //extracted();
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t离开");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t关闭");
    }


    private static void extracted() {
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t离开");
            }, String.valueOf(i)).start();
        }

        System.out.println(Thread.currentThread().getName() + "\t关闭");
    }
}
